<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <%@ include file="/commons/basejs.jsp" %>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>标签管理</title>
    <script type="text/javascript">

    </script>
</head>
<body>
<script type="text/javascript">
    var _editor;
    var _editorTwo;
    $(function() {
        $("#specialDetailAddLoc").val(selectLocId);
        $("#specialDetailAddCityId").val(selectCityId);
        console.log( "addlocid:"+$("#specialDetailAddLoc").val());
        console.log("addcityid:"+$("#specialDetailAddCityId").val());

        $('.type2').hide();
        $('.click1').hide();
       /* $("#specialDetailAddLoc").combobox({
            onSelect:function(record){*/
                /*console.log(record.id);*/
                var idStr = selectLocId;
                var id = idStr.split("_")[1];
                console.log("id:"+id);

                if(id == '0'){
                    $('.type2').hide();
                }else if(id == '1'){
                    $('.type2').hide();
                    $('.type1').show();
                }else if(id == '2'){
                    $('.type2').show();
                }

          /*  }
        });*/
        $("#specialDetailAddClickType").combobox({
            onSelect:function(record){
                console.log(record);
                var id = record.value;

                if(id == '0'){
                    $('.click1').hide();
                    $('.click0').show();
                }else if(id == '1'){
                    $('.click0').hide();
                    $('.click1').show();
                }else if(id == '2'){
                    $('.click1').hide();
                    $('.click0').hide();
                }
            }
        });

        $('#areaInfoAddPid').combotree({
            url : '${path }/areaInfo/allTree.do',
            parentField : 'pid',
            lines : true,
            panelHeight : 'auto'
        });





        //重新实例化一个编辑器，防止在上面的editor编辑器中显示上传的图片或者文件
        _editor = UE.getEditor('upload_ue',{
            serverUrl:"${path}/file/upload.do?compress=1"
        });

        _editor.ready(function () {
            //设置编辑器不可用
            // _editor.setDisabled();
            //隐藏编辑器，因为不会用到这个编辑器实例，所以要隐藏
            _editor.hide();
            //侦听图片上传
            _editor.addListener('beforeInsertImage', function (t, arg) {
                //有多少张图片arg.length就是多大
                $("#picture").val(arg[0].src);
                $("#logoUrl").attr('src',arg[0].src);
            });
        });



        //重新实例化一个编辑器，防止在上面的editor编辑器中显示上传的图片或者文件
        _editorTwo = UE.getEditor('upload_ue_two',{
            serverUrl:"${path}/file/upload.do?compress=1"
        });

        _editorTwo.ready(function () {
            //设置编辑器不可用
            // _editor.setDisabled();
            //隐藏编辑器，因为不会用到这个编辑器实例，所以要隐藏
            _editorTwo.hide();
            //侦听图片上传
            _editorTwo.addListener('beforeInsertImage', function (t, arg) {
                //有多少张图片arg.length就是多大
                $("#pictureTwo").val(arg[0].src);
                $("#logoUrlTwo").attr('src',arg[0].src);
            });
        });
        
    });

    //弹出图片上传的对话框
    function upImage() {
        var myImage = _editor.getDialog("insertimage");
        myImage.open();
    }
    //弹出图片上传的对话框
    function upImageTwo() {
        var myImage = _editorTwo.getDialog("insertimage");
        myImage.open();
    }

    function saveSpecialDetailFun() {
        console.log("addSpecialDetailFunStart");
//       var locIdStr =  $("#specialDetailAddLoc").combobox('getValue');
       var locIdStr =  selectLocId;
       var  locId = locIdStr.split("_")[0];
        console.log("locId:"+locId);
        var clickType =  $("#specialDetailAddClickType").combobox('getValue');
        console.log("clickType:"+clickType);
       if(locId == '0'){
            $('.val1').val("");
            $('.val2').val("");
        }else if(locId == '1'){
            $('.val2').val("");
        }
        console.log("flag1");

        if(clickType == '0'){
            $('.clickVal1').val("");
        }else if(clickType == '1'){
            $('.clickVal0').val("");
        }else if(clickType == '2'){
            $('.clickVal0').val("");
            $('.clickVal1').val("");
        }
        console.log("flag2");

        $('#specialDetailAddForm').form("submit",{
            url : '${path }/special/specialAdd.do',
            onSubmit : function() {
                console.log("flag3");
                progressLoad();
                var isValid = $(this).form('validate');
                if (!isValid) {
                    progressClose();
                }
                return isValid;
            },
            success :function (result) {
                console.log("flag4");
                progressClose();
                result = $.parseJSON(result);
                if (result.success) {
                    $('#specialDetailAddFormPage').dialog('close');
                    reloadSpecialDataGrid();
                } else {
                    var form = $('#specialDetailForm');
                    parent.$.messager.alert('提示', result.msg, 'warning');
                }
            }
        });
    }
    function cancelSpecialDetailFun() {
        $('#specialDetailAddFormPage').dialog('close');
    }



    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    UE.getEditor('editor_content',{
        serverUrl:"${path}/file/upload.do"
    });


</script>
<div style="padding: 3px;">
    <form id="specialDetailAddForm" method="post">
        <table class="grid" style="height: 270px">

            <tr>
               <%-- <td>位置</td>
                <td><input id="specialDetailAddLoc" name="specialLocIdStr" type="text" class="easyui-combobox" data-options="required:true,width:140,height:29,editable:false,panelHeight:'auto',valueField:'id',textField:'name',url:'${path }/special/findLocList.do?typeValue=0,1,2'"/></td>
               --%>

                <td>排序</td>
                <td>
                    <input id="specialDetailAddLoc" name="specialLocIdStr" type="hidden" >
                    <input id="specialDetailAddCityId" name="cityId" type="hidden" >
                    <input id="specialDetailAddOrd" name="ord" value="0"  class="typeAll easyui-numberspinner" style="width: 140px; height: 29px;" required="required" data-options="editable:true">
                </td>
            </tr>


            <tr>
                <td>图片</td>
                <td>
                    <div id="upload_ue"></div>
                    <div><img id="logoUrl" src="" height="80" width="80"></div>
                    <input type="hidden" id="picture" name="img1" />
                    <input type="button" onclick="upImage();" value="上传图片">
                </td>

                <td>预留图片</td>
                <td>
                    <div id="upload_ue_two"></div>
                    <div><img id="logoUrlTwo" src="" height="80" width="80"></div>
                    <input type="hidden" id="pictureTwo" name="img2" />
                    <input type="button" onclick="upImageTwo();" value="上传图片">
                </td>
            </tr>
            <tr>
                <td>类型</td>
                <td>
                    <select id="specialDetailAddClickType" name="clickType" class="easyui-combobox" data-options="width:140,height:29,editable:false,panelHeight:'auto'">
                        <option value="0">url链接</option>
                        <option value="1">富文本</option>
                        <option value="2">无</option>
                    </select>
                </td>

                <td class="clickAll click0">url</td>
                <td class="clickAll click0"><input id="specialDetailAddUrl" name="url" type="text"  class="clickVal0 easyui-validatebox span2"  ></td>


            </tr>



            <tr class="type1 type2">
                <td>标题</td>
                <td><input id="specialDetailAddTitle1" name="title1" type="text"  class="val1 easyui-validatebox span2"  ></td>


                <td>预留标题</td>
                <td><input id="specialDetailAddTitle2" name="title2" type="text"  class="val1 easyui-validatebox span2"  ></td>
            </tr>
            <tr class="type2">
                <td>备注</td>
                <td><input id="specialDetailAddDes1" name="des1" type="text"  class="val2 easyui-validatebox span2"  ></td>

                <td>预留备注</td>
                <td><input id="specialDetailAddDes2" name="des2" type="text"  class="val2 easyui-validatebox span2"  ></td>
            </tr>

            <tr>


                <td class="clickAll click1" colspan="4" >
                    <textarea id="editor_content" name="content" style="height:300px;"></textarea>
                </td>
            </tr>

        </table>
        <div style="margin-top: 20px;text-align: center">
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'", onclick="saveSpecialDetailFun()">保存</a>
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'", onclick="cancelSpecialDetailFun()">取消</a>
        </div>
    </form>

</div>
</body>

</html>